package com.sangeng.service.impl;

import com.sangeng.service.MenuService;
import com.sangeng.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("ps")
public class PermissionService {
    @Autowired
    private MenuService menuService;
    /**
     * 判断当前用户是否有相应的权限
     * @param permission
     * @return
     */
    public boolean hasPermission(String permission){
        //如果是超级管理员，那么什么权限都有，不用校验，直接返回true
        if(SecurityUtils.isAdmin()){
            return true;
        }
        //否则，查询用户相应的权限表，查看权限表中是否有包含当前的权限
        List<String> permissions = menuService.selectPermsByUserId(SecurityUtils.getUserId());
        return permissions.contains(permission);
    }

}
